import pymysql


class PyMysql():
    def __init__(self, config=None, db='gards_db', ):
        if config == None:
            config = {
                'host': 'localhost',
                'port': 3306,
                'user': 'root',
                'password': 'Root123@',
                'db': db,
                'charset': 'utf8mb4',
                'cursorclass': pymysql.cursors.DictCursor,
            }
            self.connection = pymysql.connect(**config)

    def get_connection(self):
        return self.connection

    def select(self, sql, params):
        with self.connection.cursor() as cursor:
            cursor.execute(sql, params)
            result = cursor.fetchone()
            self.connection.commit()
            return result